<template>
	<view>
		<view class="address" style="height: 120rpx;" v-for="item in addresslist" :key="item.id">
			<view @click="isaddress(item.id)">
				<view class="address-on" style="margin-left: 50rpx;">
					{{item.name}} <span style="font-size: 20rpx;margin-left: 50rpx;">{{item.tel}}</span>
					<span v-if="item.isUse==1" style="font-size: 25rpx;margin-left: 50rpx;">默认</span>
				</view>
				<view style="font-size: 20rpx;margin-left: 50rpx;margin-top: 10rpx;" class="address-under">
					{{item.cityStr}}
				</view>
			</view>

			<view class="right" style="margin-top: 15rpx;margin-right: 25rpx;">
				<view class="icon edit" @tap.stop="edit(item.id)">
					<image style="width: 40rpx;height: 40rpx;" src="../../../static/icons/edit.png" mode=""></image>
				</view>
			</view>
		</view>
		<navigator url="./edit/index">
			<view class="floot">
				新增地址
			</view>
		</navigator>

	</view>
</template>

<script>
	import MineApi from '@/api/mine/index.js'
	export default {
		data() {
			return {
				userinfo: [],
				addresslist: []
			};
		},
		methods: {
			getaddresslist() {
				MineApi.addersslist({
					userId: this.userinfo.data.id
				}).then((res) => {
					console.log(res)
					this.addresslist = res.data.data
					this.isaddress()
				})
			},
			edit(value) {
				uni.navigateTo({
					url: '/pages/mine/address/edit/index?id=' + value,
				})
			},
			isaddress(id) {
				if (id) {
					var list = this.addresslist.find(item => item.id == id)
					uni.setStorageSync('address_key', list);
					uni.navigateTo({
						url: '/pages/mine/order/detail/index',
					})
				} else {
					var list = this.addresslist.find(item => item.isUse == '1')
					uni.setStorageSync('address_key', list);
				}

			}
		},

		onLoad() {
			this.userinfo = uni.getStorageSync('storage_key');
			this.getaddresslist()

		}
	}
</script>

<style lang="scss">
	page {
		background: #f1ece7;
	}

	.address {
		display: flex;
		justify-content: space-between;
	}

	.floot {
		width: 600rpx;
		height: 80rpx;
		border-radius: 50rpx;
		color: #fff;
		position: fixed;
		bottom: 20rpx;
		left: 70rpx;
		line-height: 80rpx;
		text-align: center;
		background: #354e44;
	}
</style>
